package com.wsx.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wsx.common.R;
import com.wsx.entity.Employee;
import com.wsx.mapper.EmployeeMapper;
import com.wsx.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    /*
        根据用户名查询Employee用户
     */
    @Override
    public Employee getSelectByName(String username) {
        return employeeMapper.getSelectByName(username);
    }

    @Override
    public int insertEmployee(Employee employee) {
        return employeeMapper.insertEmployee(employee);
    }

    @Override
    public PageInfo getSelectByMybatisPage(int page, int pageSize) {
        //开启分页，然后拦截查询语句添加limit关键字，外面可以看到第一个查询语句和分页查询语句（带limit）
        //Page<Object> page = PageHelper.startPage(1, 4);   //返回值只能看到部分分页相关数据
        PageHelper.startPage(page, pageSize);
        //查询所有，Eample是根据条件查询，如果没有条件，就是查询所有
        List<Employee> list = employeeMapper.getSelectByAll();
        PageInfo<Employee> pageInfo=new PageInfo(list);
        //System.out.println(page);
        System.out.println(pageInfo);

        return pageInfo;
    }

    @Override
    public int updateByEmployee(Employee employee) {
        return employeeMapper.updateByEmployee(employee);
    }

}
